// +----------------------------------------------------------------------
// | Manong.Cloud [ 领酷码农云 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.manong.cloud All rights reserved.
// +----------------------------------------------------------------------
// | Author: 稻草人 <qinuoyun@qq.com>
// +----------------------------------------------------------------------
// | Member: 围棋 飘逸者 Loumt Silence24
// +----------------------------------------------------------------------
class Company extends CommonModels {
  /**
   * 用于字段处理
   * @return {[type]} [description]
   */
  tableFields() {
    return {
      "building_id": {
        "label": "楼宇ID",
        "type": "int(11)"
      },
      "region_id": {
        "label": "辖区ID",
        "type": "int(11)"
      },
      "name": {
        "label": "公司名称",
        "type": "varchar(50)"
      },
      "code": {
        "label": "公司统一社会码",
        "type": "varchar(50)"
      },
      "house_address": {
        "label": "门牌地址",
        "type": "varchar(255)"
      },
      "is_registered": {
        "label": "是否注册 1是 2否",
        "type": "int(1)",
        "defaultValue": 1
      },
      "registered_address_status": {
        "label": "是否与注册地址一致 1是 2否",
        "type": "int(1)",
        "defaultValue": 1
      },
      "registered_address": {
        "label": "注册地址",
        "type": "varchar(255)"
      },
      "people_number": {
        "label": "人数",
        "type": "varchar(50)"
      },
      "type": {
        "label": "公司类型",
        "type": "varchar(50)"
      },
      "industry": {
        "label": "所属行业",
        "type": "varchar(50)"
      },
      "industry_label": {
        "label": "行业标签",
        "type": "varchar(255)"
      },
      "business_scope": {
        "label": "经营范围",
        "type": "varchar(50)"
      },
      "registration_authority": {
        "label": "登记机关",
        "type": "varchar(50)"
      },
      "approve_time": {
        "label": "核准日期",
        "type": "varchar(50)"
      },
      "head_office": {
        "label": "是否是总公司  1是  2否",
        "type": "int(1)",
        "defaultValue": 1
      },
      "business_license": {
        "label": "营业执照",
        "type": "varchar(255)"
      },
      "legal_person": {
        "label": "法人",
        "type": "varchar(50)"
      },
      "legal_person_mobile": {
        "label": "法人联系方式",
        "type": "varchar(50)"
      },
      "legal_person_certificate_type": {
        "label": "法人证件类型 1身份证 2护照 3驾照",
        "type": "int(1)",
        "defaultValue": 1
      },
      "legal_person_certificate_code": {
        "label": "法人证件号",
        "type": "varchar(50)"
      },
      "legal_person_status": {
        "label": "法人是否有前科 1是  2否",
        "type": "int(1)",
        "defaultValue": 2
      },
      "legal_person_nationality": {
        "label": "法人国籍",
        "type": "varchar(50)"
      },
      "control_person": {
        "label": "控制人",
        "type": "varchar(50)"
      },
      "control_person_mobile": {
        "label": "控制人联系方式",
        "type": "varchar(50)"
      },
      "control_person_certificate_type": {
        "label": "控制人证件类型 1身份证 2护照 3驾照",
        "type": "int(1)",
        "defaultValue": 1
      },
      "control_person_certificate_code": {
        "label": "控制人证件号",
        "type": "varchar(50)"
      },
      "control_person_status": {
        "label": "控制人是否有前科 1是  2否",
        "type": "int(1)",
        "defaultValue": 2
      },
      "control_person_nationality": {
        "label": "控制人国籍",
        "type": "varchar(50)"
      },
      "landlord": {
        "label": "房东",
        "type": "varchar(50)"
      },
      "landlord_mobile": {
        "label": "房东电话",
        "type": "varchar(50)"
      },
      "landlord_certificate_type": {
        "label": "房东证件类型 1身份证 2护照 3驾照",
        "type": "int(1)",
        "defaultValue": 1
      },
      "landlord_certificate_code": {
        "label": "房东证件号",
        "type": "varchar(50)"
      },
      "join_time": {
        "label": "入驻时间",
        "type": "datetime"
      },
      "expire_time": {
        "label": "到期时间",
        "type": "datetime"
      },
      "fee_status": {
        "label": "物业费是否正常 1是 2否",
        "type": "int(1)",
        "defaultValue": 1
      },
      "lease_contract": {
        "label": "租赁合同",
        "type": "varchar(255)"
      },
    }
  }

  /**
   * 实现数据验证
   * 需要数据写入，必须在rules添加对应规则
   * 在控制中执行[模型]->attributes = $postData;
   * 否则会导致验证不生效，并且写入数据为空
   * @return [type] [description]
   */
  rules() {
    return {}
  }

  /**
   * @inheritdoc
   */
  tableName() {
    return '{{%company}}';
  }

  getBuilding() {
    return this.belongsTo({name: M('Building').tableName(), as: 'building_info'}, 'building_id', 'id', ['id', 'name']);
  }

  getRegion() {
    return this.belongsTo({
      name: M('Region').tableName(),
      as: 'region_info'
    }, 'region_id', 'id', ['id', 'province', 'city', 'area', 'street', 'province_name', 'city_name', 'area_name', 'street_name']);
  }

  getRoom() {
    return this.hasMany({name: M('Building.Room').tableName(), as: 'rooms'}, 'company_id', 'id', ['id', 'name']);
  }
}

export default Company;
